// pages/functions/jumpPage/popularize/memberInfo.js
import { find } from '../../../../api/member'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    isWater: false,
    memberInfo: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.data.id = options.id
    if (app.SCOPE_TYPE === 2) {
      this.setData({
        isWater: true
      })
    }
    this.loadMemberInfo()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },
  loadMemberInfo() {
    const that = this
    find(this.data.id).then(res => {
      console.log(res);
      that.setData({
        memberInfo: res.data.member
      })
    })
  },
  toAddress(e) {
    wx.navigateTo({
      url: `/pages/functions/jumpPage/address/address?id=${this.data.id}&btnDisabled=${true}`
    })
  },
  toWater() {
    this.checkLogin(() => {
      wx.navigateTo({
        // url: '/pages/functions/jumpPage/popularize/waterTicket',
        url: `/pages/functions/jumpPage/popularize/waterTicket?id=${this.data.id}`
      })
    })
  },
  toAdjust() {
    wx.navigateTo({
      url: `/pages/functions/jumpPage/popularize/adProduct?id=${this.data.id}`
    })
  },
  toEmptyBarrel() {
    wx.navigateTo({
      url: `/pages/member/emptyBarrel/emptyBarrel?id=${this.data.id}`
    })
  },
  toMemberOrder() {
    wx.navigateTo({
      url: `/pages/functions/jumpPage/popularize/order?id=${this.data.id}`
    })
  },
  toWithdrawal() {
    wx.navigateTo({
      url: `/pages/functions/jumpPage/popularize/list?id=${this.data.id}&name=${this.data.memberInfo.name}`
    })
  },
  checkLogin(callback) {
    if (app.globalData.token == null) {
      wx.navigateTo({
        url: '/pages/login/index',
      })
    } else {
      if (callback) {
        callback()
      }
    }
  },
})